﻿using System.Configuration;
using System.IO;
using System.Reflection;
using log4net;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Patriq.Msmq.Router.Core;

namespace Patriq.Msmq.Router.Console
{
    class Program
    {
        private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        static void Main(string[] args)
        {
            var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var configPath = Path.Combine(basePath, "log4net.xml");
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(configPath));
            Logger.Info("Initializing the QueueForwarder");

            var container = new UnityContainer();
            var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Configure(container);
            var routeEngine = container.Resolve<IRouteEngine>();
            Logger.Info("Starting up");
            routeEngine.Start();
            System.Console.WriteLine("Press any key to exit");
            System.Console.ReadKey();
            Logger.Info("Shutting down");
            routeEngine.Stop();
            routeEngine.Dispose();
        }
    }
}
